/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Proveedores;

import Clientes.BusquedaCliente;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author alma
 */
public class BusquedaProveedor extends javax.swing.JInternalFrame {

    /**
     * Creates new form BusquedaProveedor
     */
    public String consulta ;
    public java.sql.ResultSet rs ;
    public ProveedorBD procProv = new ProveedorBD();
    
    public BusquedaProveedor() {
        initComponents();
        rNombre.setSelected(true);
        consulta = "WHERE p.NombreProveedor LIKE '%";
    }

  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tBusqueda = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tcontenido = new javax.swing.JTable();
        rNombre = new javax.swing.JRadioButton();
        rNit = new javax.swing.JRadioButton();

        jLabel1.setFont(new java.awt.Font("Lucida Bright", 1, 18)); // NOI18N
        jLabel1.setText("Busqueda Proveedor");

        jLabel2.setText("Buscar:");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/search_08_24.png"))); // NOI18N
        jButton1.setText("Buscar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        Tcontenido.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "No. NIT", "Nombre", "Dirección", "Telefono"
            }
        ));
        jScrollPane1.setViewportView(Tcontenido);

        rNombre.setText("Nombre");
        rNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rNombreActionPerformed(evt);
            }
        });

        rNit.setText("NIT");
        rNit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rNitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 641, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(jLabel2)
                        .addGap(109, 109, 109)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(rNombre)
                                .addGap(84, 84, 84)
                                .addComponent(rNit))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(jButton1))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(300, 300, 300)
                        .addComponent(jLabel1)))
                .addContainerGap(81, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rNombre)
                    .addComponent(rNit))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(71, 71, 71))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      
         Vector<String> tableHeaders = new Vector<String>();
    Vector tableData = new Vector();
    tableHeaders.add("NIT");
    tableHeaders.add("Nombre"); 
    tableHeaders.add("Direccion");
    tableHeaders.add("Telefono");
    
       
        try {
          System.out.print(consulta+tBusqueda.getText()+"%'");
          rs = procProv.VerdatosProveedor(consulta+tBusqueda.getText()+"%'");
          while (rs.next()){
             
        Vector<Object> oneRow = new Vector<Object>();
        oneRow.add(rs.getInt("NitProveedor"));
        oneRow.add(rs.getString("NombreProveedor"));
        oneRow.add(rs.getString("DireccionProveedor"));
        oneRow.add(rs.getString("TelefonoProveedor"));
        tableData.add(oneRow);
       }
        Tcontenido.setModel(new DefaultTableModel(tableData, tableHeaders));
        
       
        
        
    
        } catch (SQLException ex) {
            Logger.getLogger(BusquedaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void rNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rNombreActionPerformed
      if(rNombre.isSelected()){
         rNit.setSelected(false);
         consulta = "WHERE p.NOMBRE LIKE '%";
        }
    }//GEN-LAST:event_rNombreActionPerformed

    private void rNitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rNitActionPerformed
       if(rNit.isSelected()){
         rNombre.setSelected(false);
         consulta = "WHERE p.NitProveedor LIKE '%";
        }  
        
    }//GEN-LAST:event_rNitActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Tcontenido;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton rNit;
    private javax.swing.JRadioButton rNombre;
    private javax.swing.JTextField tBusqueda;
    // End of variables declaration//GEN-END:variables
}
